package 电话号码的字母组合;

import java.util.ArrayList;
import java.util.List;

class Solution {
    String[] hash = {"","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
    List<String> ret;
    StringBuffer path;
    public List<String> letterCombinations(String digits) {
        ret = new ArrayList<>();
        path = new StringBuffer();
        if(digits.length() == 0){
            return ret;
        }
        dfs(digits, 0);
        return ret;
    }

    public void dfs(String str, int pos){
        if(pos == str.length()){
            ret.add(path.toString());
            return;
        }
        String cur = hash[str.charAt(pos) - '0'];
        for(int i = 0; i < cur.length(); i++){
            path.append(cur.charAt(i));
            dfs(str, pos + 1);
            path.deleteCharAt(path.length() - 1);
        }
    }
}